package com.xhsd.zlong.generatepinyin;

import net.sourceforge.pinyin4j.PinyinHelper;

public class PinyinUtils {
	
	/**
	 * 一个String 数组转换为拼音
	 */
	public static void topinyin(String[] names){

		for (String name : names) {
			topinying(name);
		}
	}

	
	/**
	 * 一个String转换为拼音
	 */
	public static void topinying(String name) {
		
		for(int i=0;i<name.length();i++){
			
			char c = name.charAt(i);
			
			String[] result = PinyinHelper.toHanyuPinyinStringArray(c);
			
			outPrint(result);
			
		}
		
		System.out.println("\n");				//换行
		
	}

	/**
	 * 打印String数组
	 */
	private static void outPrint(String[] result) {
		String before = "";
		
		for (String s : result) {
			s = s.substring(0,s.length()-1);
			
			if(!s.equals(before)){
				before=s;
				System.out.print(s);
			}
		}
	}
}
